import Vue from 'vue'
import axios from 'axios'
import vueRouter from 'vue-router'
import filters from './lib/filters'
import iView from 'iview'
import hljs from 'highlight.js'
import 'highlight.js/styles/default.css'
import 'iview/dist/styles/iview.css'
import routerMap from './lib/routers'
/* eslint-disable no-new */

Vue.use(iView)
Vue.use(vueRouter)

//添加axios
Vue.prototype.$http = axios;
//过滤器
Object.keys(filters).forEach(k => Vue.filter(k, filters[k]));
Vue.directive('highlightjs', function() {
        let blocks = this.el.querySelectorAll('pre code');
        Array.prototype.forEach.call(blocks, hljs.highlightBlock);
    }),
    Vue.directive('highlight', function(value) {
        let el = this.el
        if (value) {
            let oValue = null
            if (typeof(value) === "string") {
                oValue = value
            } else {
                oValue = JSON.stringify(value, null, 4)
            }
            el.innerHTML = '<pre><code class="json hljs">' + hljs.highlight("json", oValue, true).value + '</code></pre>'
        }
    })
let router = new vueRouter({
    hashbang: true,
    history: false,
    saveScrollPosition: true,
    transitionOnLoad: true
});

let app = Vue.extend({});
routerMap(router);
router.start(app, '#app');